function getQuotaData(nodes){
	var quotas = [];
	for(var o in nodes){
		var node = nodes[o];
		var quota = node;
		if(node.checked){
			quotas.push(quota);
			if(node.children || node.isParent){
				getCheckedNodes(node.children, quota);
			}
		}
	}
	function getCheckedNodes(nodes, quotas){
		quotas.children = [];
		for(var o in nodes){
			var node = nodes[o];
			var quota = node;
			if(node.checked){
				quotas.children.push(quota);
				if(node.children || node.isParent){
					getCheckedNodes(node.children, quota);
				}
			}
		}
	}
	return quotas;
}

//封装页面初始化开始加载指标的方法
function getQuotas(pageCode, loadData, container,monitorType){
	$.ajax({
		url : "quota/getQuotas.dhc",
		async : false,
		data : {'pageCode': pageCode},
		type : "POST",
		success : function(result) {
			if(result.data.length==0){
				drgUI.error("没有配置指标,请联系管理员") ;
			}
			totalQuota = arrayToTree(result.data, "id", "pid");
			var zTrees = $.extend(true, [], totalQuota);
			totalQuota = getQuotaData(totalQuota);
			loadData(totalQuota);
			if(container=="depGroupCli-ul_0"||container=="departmenthosp-ul"||container=="depGroupCli-ul_all"||container=="depCliList-ul"){
				loadQuotaSettings(pageCode, loadData, zTrees, container,monitorType);
			}
		}
	});
}
//加载指标配置页面
function loadQuotaSettings(pageCode, loadData, zTrees, container,monitorType){
	var quotaSettingBtn = $('<div class="btn-clickable" style="margin:2px;">指标配置<i class="fa fa-cog fa-lg"></i></div>');
	$("#"+tabId+" #"+container).before(quotaSettingBtn);
	quotaSettingBtn.bind("click", function(){
		$.post(contextPath+"/pages/common/quota-tree.jsp").done(function(data){
			var dialog  = $(data);
			dialog.find(".modal-title").html("指标配置选项");
			var str = '';
			str += '<div class="zTreeDemoBackground">';
			str += '<ul id="treeDemo" class="ztree"></ul>';
			str += '</div>"';
			dialog.find(".echartscq").html(str);
			var setting = {
					view: {
						selectedMulti: false
					},
					check: {
						enable: true
					}
				};
			$.fn.zTree.init(dialog.find("#treeDemo"), setting, zTrees);
			dialog.find('#save').on('click', function(){
				dialog.find('#save').attr("disabled", '');
				var zTree = $.fn.zTree.getZTreeObj("treeDemo");
				zTrees = zTree.getNodes();
				var nodes =  $.extend(true, [], zTrees);
				totalQuota = getQuotaData(nodes);
				var zTreeSimp = zTree.transformToArray(zTrees);
				var ajaxCount = zTreeSimp.length;
				var ajaxS = 0;
				var errorLog;
				for(var o in zTreeSimp){
					var node = zTreeSimp[o];
					node.pageCode = pageCode;
					$.post(contextPath + "/quota/saveQuotas.dhc", {param: JSON.stringify(node)}).done(function(data){
						ajaxS ++;
						if(!data.success){
							errorLog += "指标("+node.code+")报错\n"+data.errorMessage;
							errorLog += "\n";
						}
					})
				}
				var timer = setInterval(function(){
					if(ajaxS == ajaxCount){
						clearInterval(timer);
						if(errorLog){
							dialog.modal('hide');
							drgUI.error("没有配置指标,请联系管理员") ;
						}else{
							dialog.trigger('complete');
						}
					}
				}, 500);
			}).end().modal({
				keyboard : false
			}).on({
				'hidden.bs.modal' : function() {
					dialog.remove();
				},
				'complete' : function() {
					dialog.modal('hide');
					loadData(totalQuota,"all");
	            }
			});
			dialog.find('#clear').on('click', function(){
				drgUI.confirm({
        			content : '即将恢复默认页面指标配置，是否恢复？',
        			callSure : function() {
        				$.post(contextPath + "/quota/clearQuotaSettings.dhc", {pageCode: pageCode}).done(function(data){
        					$.post(contextPath + "/quota/getQuotas.dhc", {pageCode: pageCode}).done(function(data_1){
        						if(data_1.data.length==0){
        							drgUI.error("没有配置指标,请联系管理员") ;
        							return;
        						}
        						totalQuota = arrayToTree(data_1.data, "id", "pid");
        						var zTrees = $.extend(true, [], totalQuota);
        						$.fn.zTree.init(dialog.find("#treeDemo"), setting, zTrees);
        					});
        				});
        			}
        		});
			});
		})
	});
}

/*
 * 加载页面全院部分页面数据
 */
function loadDepartmentAllQuota(monitorType, totalQuota, divId,commonul,pardepgroupCode) {
	var param=drgUI.setAjaxData(tabId);
	var str = '';
	var ul = '';
	for (var o in totalQuota) {
		var quotaTypes = totalQuota[o].children;
		if (totalQuota.length > 0) {
			// 拼接ul
			if (o == 0) {
				ul += '<li role="presentation" class="active">';
			} else {
				ul += '<li role="presentation">';
			}
			ul += '<a href="#' + totalQuota[o].code +divId  +'QuaId-hosp' + tabId
					+ '" role="tab" data-toggle="tab" class="top-tab">'
					+ totalQuota[o].name + '</a>';
			ul += '</li>';
	       $("#" + tabId +" #"+commonul).html(ul);
			// 开始拼接div
			if (o == 0) {
				str += '<div role="tabpanel" class="tab-pane active" id="'
						+ totalQuota[o].code+divId  + 'QuaId-hosp' + tabId + '">';
			} else {
				str += '<div role="tabpanel" class="tab-pane" id="'
						+ totalQuota[o].code+divId  + 'QuaId-hosp' + tabId + '">';
			}
			str += '<div class="paddingd10">';
			str += '<div class="row" >';
		}
		for (var o in quotaTypes) {
			var quotas = quotaTypes[o];
			str += ' <div class="col-xs-4"> ';
			str += '     <div class="infocq"> ';
			str += '         <div class="tii margind10'
				if(quotas.name==='产能'){
					str += ' blue-bg"><span><i class="fa fa-users fa-lg"></i>';
				} else if(quotas.name==='效率'){
					str += ' green-bg"><span><i class="fa fa-stethoscope fa-lg"></i>';
				} else if(quotas.name==='安全'){
					str += ' red-bg"><span><i class="fa fa-heartbeat fa-lg"></i>';
				} else {
					str += '"><span>';
				}
			str+= quotas.name + '</span></div> ';
			str += '         <div class="ci"> ';
			for (var o1 in quotas.children) {
				var quota = quotas.children[o1];
				var quotaCode = quota.code;
				var quotaName = quota.name;
				var quotaType = quota.type;
				var isLink = quota.islink;
				if(quotaCode=='FeeEffContri')
				{//费用消耗指数贡献度  汇总时 有当前指标直接跳过  不加载
					continue;
				}
				str += '             <div class="row contotalcq2"> ';
				str += '                <div class="col-xs-6">'+ quotaName + '</div> ';
				if("ratio"==quotaType){
					str += '                 <div class="col-xs-6" id="'+quotaCode+'-value">'+getQuotaValue(quotaCode, quotaName, monitorType,isLink, function(value, valuecc, code,name,isLink){
						$("#" + tabId + " #" + divId + " #"+code+"-value").html(comparePercent(value, valuecc));
					})+'</div> ';
				}else{
					str += '                 <div class="col-xs-6" id="'+quotaCode+'-value">'+getQuotaValue(quotaCode, quotaName, monitorType,isLink, function(value, valuecc, code, name,isLink){
						if(isLink==1){
							var code_dtl = "";
							if(param.deps==""){//科室组
								code_dtl = param.depGroupCode;
							}else{
								if(pardepgroupCode==null){
									code_dtl = param.deps;
								}else {
									code_dtl= pardepgroupCode;
								}
							}
							
							var str = compareValue(value, valuecc);//数值比较的字符串
							var reg = /<span class= \"number\".*?>.*?<\/span>/; //正则表达式 匹配 html 中 class = "number" 的span标签
							var num = str.match(reg);//数字串
							if(num==null){
								num = "";
								$("#" + tabId + " #" + divId + " #"+code+"-value").html(str);
							}else{
								num = num[0];
								var symbol = str.replace(reg, "");//符号串
								// 当前值为0时不加链接
								if(Number(value)==0){
									$("#" + tabId + " #" + divId + " #"+code+"-value").html(num+symbol);
								} else {
									$("#" + tabId + " #" + divId + " #"+code+"-value").html("<a href=\"javascript:loadDepCaseDtl('"+name+"','"+code_dtl+"','"+monitorType+"', '"+code+"')\">"+num+"</a>"+symbol);
								}
							}
						}else{
							if(value == undefined){
								value = 0 ;
							}
							$("#" + tabId + " #" + divId + " #"+code+"-value").html(compareValue(value, valuecc));
						}
					})+'</div> ';
				}
				str += '             </div> ';
			}
			str += '         </div> ';
			str += '     </div> ';
			str += ' </div> ';
		}
		if (totalQuota.length > 0) {
			str += '</div>';
			str += '</div>';
			str += '</div>';
		}
	}
	$("#" + tabId + " #" + divId).html(str);
}

function getQuotaValue(quotaCode, quotaName, monitorType,isLink, callback){
	var param=drgUI.setAjaxData(tabId);
	param.monitorType=monitorType;
	param.quotaCode=quotaCode;
	$.post(contextPath + "/DrgsIndexCal/indexCal.dhc",param).done(function(data) {
		if(data.success){
			if(data.data.length>0){
				data = data.data[0];
				callback(data.QuotaValue, data.QuotaValuecc, quotaCode, quotaName,isLink);
			}else{
				callback("", "", quotaCode, quotaName,isLink);
			}
		}else{
			callback("", "", quotaCode, quotaName,isLink);
		}
	});
	return "";
}

function loadDepGrouppartmentAllQuota(monitorType, totalQuota, divId,commonul) {
	var str = '';
	var ul = '';
	for (var o in totalQuota) {
		var quotaTypes = totalQuota[o].children;
		if (totalQuota.length > 0) {
			// 拼接ul
			if (o == 0) {
				ul += '<li role="presentation" class="active">';
			} else {
				ul += '<li role="presentation">';
			}
			ul += '<a href="#' + totalQuota[o].code + 'QuaId-depgroup' + tabId+ '" role="tab" data-toggle="tab" class="top-tab">'+ totalQuota[o].name + '</a>';
			ul += '</li>';
	       $("#" + tabId +" #"+commonul).html(ul);
			// 开始拼接div
			if (o == 0) {
				str += '<div role="tabpanel" class="tab-pane active" id="'
						+ totalQuota[o].code + 'QuaId-depgroup' + tabId + '">';
			} else {
				str += '<div role="tabpanel" class="tab-pane" id="'
						+ totalQuota[o].code + 'QuaId-depgroup' + tabId + '">';
			}
			str += '<div class="paddingd10">';
			str += '<div class="row" >';
		}
		for (var o in quotaTypes) {
			var quotas = quotaTypes[o];
			str += ' <div class="col-xs-4"> ';
			str += '     <div class="infocq"> ';
			str += '         <div class="tii margind10'
				if(quotas.name==='产能'){
					str += ' blue-bg"><span><i class="fa fa-users fa-lg"></i>';
				} else if(quotas.name==='效率'){
					str += ' green-bg"><span><i class="fa fa-stethoscope fa-lg"></i>';
				} else if(quotas.name==='安全'){
					str += ' red-bg"><span><i class="fa fa-heartbeat fa-lg"></i>';
				} else {
					str += '"><span>';
				}
			str += quotas.name + '</span></div> ';
			str += '         <div class="ci"> ';
			for (var o1 in quotas.children) {
				var quota = quotas.children[o1];
				var quotaCode = quota.code;
				var quotaName = quota.name;
				var quotaType = quota.type;
				var isLink = quota.islink;
				if(quotaCode=='FeeEffContri')
				{//费用消耗指数贡献度  汇总时 有当前指标直接跳过  不加载
					continue;
				}
				str += '             <div class="row contotalcq2"> ';
				str += '                <div class="col-xs-6">'+ quotaName + '</div> ';
				if("ratio"==quotaType){
					str += '                 <div class="col-xs-6" id="'+quotaCode+'-value">'+getQuotaValue(quotaCode, quotaName, monitorType,isLink, function(value, valuecc, code,name,isLink){
						$("#" + tabId + " #" + divId + " #"+code+"-value").html(comparePercent(value, valuecc));
					})+'</div> ';
				}else{
					str += '                 <div class="col-xs-6" id="'+quotaCode+'-value">'+getQuotaValue(quotaCode, quotaName, monitorType,isLink, function(value, valuecc, code, name,isLink){
						if(isLink==1){
							var str = compareValue(value, valuecc);//数值比较的字符串
							var reg = /<span class= \"number\".*?>.*?<\/span>/; //正则表达式 匹配 html 中 class = "number" 的span标签
							var num = str.match(reg);//数字串
							if(num==null)//没有匹配的串时 直接展示 
							{
								num = "";
								$("#" + tabId + " #" + divId + " #"+code+"-value").html(str);
							}
							else
							{
								num = num[0];
								var symbol = str.replace(reg, "");//符号串
								// 当前值为0时不加链接
								if(Number(value)==0){
									$("#" + tabId + " #" + divId + " #"+code+"-value").html(num+symbol);
								} else {
									$("#" + tabId + " #" + divId + " #"+code+"-value").html("<a href=\"javascript:loadDepCaseDtl('"+name+"','','"+monitorType+"', '"+code+"')\">"+num+"</a>"+symbol);
								}
							}
						}else{
							$("#" + tabId + " #" + divId + " #"+code+"-value").html(compareValue(value, valuecc));
						}
					})+'</div> ';
				}
				str += '             </div> ';
			}
			str += '         </div> ';
			str += '     </div> ';
			str += ' </div> ';
		}
		if (totalQuota.length > 0) {
			str += '</div>';
			str += '</div>';
			str += '</div>';
		}
	}
	$("#" + tabId + " #" + divId).html(str);
}
     
// 拼接页面布局
function loadDepartmentQuota(totalQuota, monitorName, divId,commonul) {
	var param=drgUI.setAjaxData(tabId);
	var sign=totalQuota[0].code;
	if (!monitorName)
		monitorName = ""
	if (param.compareType == "year") {
		compareName = "同期";
	} else if (param.compareType == "month") {
		compareName = "上期";
	} else if (param.compareType == "manage") {
		compareName = "绩效";
	} else if (param.compareType == "std") {
		compareName = "标杆";
	}
	var str = '';
	var ul = '';
	for (var o in totalQuota) {
		var QuotaCode = totalQuota[o].children;				
		// 拼接ul
		if (totalQuota.length > 0) {
			if (o == 0) {
				ul += '<li role="presentation" class="active">';
			} else {
				ul += '<li role="presentation">';
			}
			ul += '<a href="#' + totalQuota[o].code + 'QuaId' + tabId
			+ '" role="tab" data-toggle="tab" class="top-tab">' + totalQuota[o].name
			+ '</a>';
			ul += '</li>';
			$("#" + tabId +" #"+commonul).html(ul);
		}
		// 开始拼接div
		if (o == 0) {
			str += '<div role="tabpanel" class="tab-pane active" id="'+ totalQuota[o].code + 'QuaId' + tabId + '">';
		} else {
			str += '<div role="tabpanel" class="tab-pane" id="'
				+ totalQuota[o].code + 'QuaId' + tabId + '">';
		}

		for (var o in QuotaCode) {
			var quotas = QuotaCode[o];
			str += ' <div class="paddingd10"> ';
			str += '   <div class="tabconti';
			if(quotas.name==='产能'){
				str += ' blue-bg"><i class="fa fa-users fa-lg"></i>';
			} else if(quotas.name==='效率'){
				str += ' green-bg"><i class="fa fa-stethoscope fa-lg"></i>';
			} else if(quotas.name==='安全'){
				str += ' red-bg"><i class="fa fa-heartbeat fa-lg"></i>';
			} else {
				str += '">';
			}
			str += quotas.name + '</div> ';
			str += '   <ul class="nav nav-tabs tabconulcq" role="tablist"> ';
			for (var o1 in quotas.children) {
				var quota = quotas.children[o1];
				var quotaCode = quota.code;
				var quotaName = quota.name;
				if (o1 == 0) {
					str += '       <li role="presentation" class="active"> ';
				} else {
					str += '       <li role="presentation"> ';
				}
				str += '           <a href="#' + quotaCode + '-tc' + tabId+ '" role="tab" data-toggle="tab">' + quotaName+ '</a> ';
				str += '       </li> ';
			}
			str += '   </ul> ';
			str += '   <div class="clearfix"></div> ';
			str += '   <div class="tab-content"> ';
			for (var o1 in quotas.children) {
				var quota = quotas.children[o1];
				var quotaCode = quota.code;
				var quotaName = quota.name;
				if (o1 == 0) {
					str += '       <div role="tabpanel" class="tab-pane active" compareName="'+ compareName+ '" monitorName="'+ monitorName
					+ '" quotaName="'+ quotaName+ '" quotaCode="'+ quotaCode+ '" id="'+ quotaCode+ '-tc'+ tabId+ '"> ';
				} else {
					str += '       <div role="tabpanel" class="tab-pane" compareName="'+ compareName+ '" monitorName="'+ monitorName+ '" quotaName="'+ quotaName+ '" quotaCode="'+ quotaCode+ '" id="'+ quotaCode+ '-tc'+ tabId+ '"> ';}
					str += '           <div class="row padding100"> ';
					str += '               <div class="col-xs-6"> ';
					str += '                   <div class="echartscq" style="height:400px;width:566px;"></div> ';
					str += '               </div> ';
					str += '               <div class="col-xs-6 dataChangeSel"> ';
					str += '                   <table id="'+ quotaCode+ '-table'+ tabId+ '" class="table table-striped" cellspacing="0" width="100%" role="grid" aria-describedby="example_info"> ';
					str += '                       <caption class="contaotalsccq">'+ monitorName + quotas.name + '(' + quotaName+ ')</caption> ';
					str += '                       <thead> ';
					str += '                           <tr role="row"> ';
					str += '                               <th tabindex="0" aria-controls="example" rowspan="1" colspan="1" aria-sort="ascending">'+ monitorName + '</th> ';
					str += '                               <th tabindex="0" aria-controls="example" rowspan="1" colspan="1">本期值</th> ';
					str += '                               <th tabindex="0" aria-controls="example" rowspan="1" colspan="1">'+ compareName + '值</th> ';
					str += '                               <th tabindex="0" aria-controls="example" rowspan="1" colspan="1">增长率</th> ';
					str += '                               <th tabindex="0" aria-controls="example" rowspan="1" colspan="1">操作</th> ';
					str += '                           </tr> ';
					str += '                       </thead> ';
					str += '                       <tbody></tbody> ';
					str += '                   </table> ';
					str += '               </div> ';
					str += '           </div> ';
					str += '       </div> ';
			}
			str += '   </div> ';
			str += ' </div> ';
		}
		str += '</div>';		
	}
	$("#" + tabId + " #" + divId).html(str);
}
     
// 根据totalQuota循环加载数据
function loadDepartmentQuotaData(totalQuota, monitorType, across) {
	for (var o in totalQuota) {
		var quotaTypes = totalQuota[o].children;
		for (var o in quotaTypes) {
			var quotas = quotaTypes[o];
			for (var o1 in quotas.children) {
				var quota = quotas.children[o1];
				var quotaCode = quota.code;
				var quotaName = quota.name;
				var quotaType = quota.type;
				var isLink = quota.islink;
				loadDRGsQuotaDatasub(quotaCode, quotaName,quotaType,monitorType,across,isLink);// 最后两个参数为本页面自定义的方法，当没有方法传递时传递空字符
			}
		}
	}
}
/*
 * 为拼接好的div布局添加图表和数据表格，本方法的后三个参数functionOne为表格第一列数据链接函数名称，
 * operfunctionTwo
 */
function loadDRGsQuotaDatasub(quotaCode, quotaName,quotaType, monitorType, across,isLink) {
	var param=drgUI.setAjaxData(tabId);
	param.monitorType=monitorType;
	param.quotaCode=quotaCode;
	$.post(contextPath + "/DrgsIndexCal/indexCal.dhc", param).done(function(data) {
		     data = data.data;
		     var hasCaseDtl = isLink==1?true:false;
			 var columns = [{
				 "data" : "ccode1",
				 "fnCreatedCell": function (nTd, sData, oData, iRow, iCol) {
					 $(nTd).limit();
				 },
				 "render": function(obj, type, full) {
					 if(full.ccode==null||full.ccode=="null")
					 {
						 return "未入组";
					 }
					 else if(monitorType=="mdc"||monitorType=="adrg")
					 {//病组线   mdc或adrg
						 return "<a title ='' href=\"javascript:departmentToNextLayer("+across+",'" + monitorType + "','"+ full.ccode + "','" + full.ddesc+ "') \">" + "("+full.ccode+")"+full.ddesc + "</a>";
					 }
					 else if(monitorType=="drgs")
					 {
						 return "("+full.ccode+")"+full.ddesc;
					 }
					 else
					 {
						 if (monitorType=="dep"&&(commonLayerConfig[2]=='1'||commonLayerConfig[3]=='1')) {
							 return "<a title ='' href=\"javascript:departmentToNextLayer("+across+",'" + monitorType + "','"+ full.ccode + "','" + full.ddesc+ "') \">" + full.ddesc + "</a>";
						 } 
						 else
						 {
							 return full.ddesc;
						 }
					 }
				 }						 
				}, {
					"data" : "QuotaValue_1",
					"render":function(obj, type, full){
						full.QuotaValue=full.QuotaValue!=null?full.QuotaValue:'';//强制转换
						full.QuotaValuecc=full.QuotaValuecc!=null?full.QuotaValuecc:'';
						if(hasCaseDtl && (Number(full.QuotaValue)>0)){
							return "<a href=\"javascript:loadDepCaseDtl('"+full.ddesc+"|"+quotaName+"','"+full.ccode+"','"+monitorType+"', '"+quotaCode+"' )\">"+formatNumber(full.QuotaValue)+"</a>"
						}
						return formatNumber(full.QuotaValue);   
					}
				}, {
					"data" : "QuotaValuecc",
					"render":function(obj, type, full){
							return full.QuotaValuecc;
					}
				}, { "data": "increasing","sType": "number-fate",
                	 "render":function(obj, type, full){
	                    	if("ratio"==quotaType){
                    			 return gridcompareValuePercent(full.QuotaValue, full.QuotaValuecc);
                    		 }
          		           return gridcompareValue(full.QuotaValue, full.QuotaValuecc);
                	 }
                 },
                 {
					"data" : "OPERATION",
					 "render":function(obj, type, full){
						 if(across)
            				{//交叉的情况	科室线下各病组层次	病区线下各科室层次
							 	if (full.ccode == null) {
							 		return "<a title='入组病例' class='jumplink' href=\"javascript:alertData()\"><i class='fa fa-users'></i></a> "
									+"<a title='趋势' href=\"javascript:alertData()\" class='trend-link'><i class='fa fa-line-chart'></i></a>&nbsp;&nbsp;";
								} else {
									return "<a title='入组病例' class='jumplink' href=\"javascript:loadDetail('"+ full.ccode+ "','"+ full.ddesc+ "','"+ monitorType+ "')\"><i class='fa fa-users'></i></a> "
									+"<a title='趋势' href=\"javascript:trend('"+ full.ccode+ "', '"+ full.ddesc+ "', '"+ monitorType + "', '"+ quotaCode+ "', '"+ quotaName+ "')\" class='trend-link'><i class='fa fa-line-chart'></i></a>&nbsp;&nbsp;";
								}
            				}
	               			else
            				{
	               				if (monitorType=="mdc"||monitorType=="adrg"||monitorType=="drgs")
               					{// 科室 趋势 病例
		               					if (full.ccode == null) {
											return "<a title='科室' class='jumplink' href=\"javascript:alertData()\"><i class='fa fa-hospital-o'></i></a>&nbsp;&nbsp;"
													+"<a title='入组病例' class='jumplink' href=\"javascript:alertData()\"><i class='fa fa-users'></i></a>&nbsp;&nbsp;"
													+"<a title='趋势' href=\"javascript:alertData()\" class='trend-link'><i class='fa fa-line-chart'></i></a>";
		               					} else {
											return "<a title='科室' href=\"javascript:departmentDisToDep('"+ full.ccode+ "', '"+ full.ddesc+ "', '"+ monitorType+ "')\" class='jumplink'><i class='fa fa-hospital-o'></i></a>&nbsp;&nbsp;"								
													+"<a title='入组病例' class='jumplink' href=\"javascript:loadDetail('"+ full.ccode+ "','"+ full.ddesc+ "','"+ monitorType+ "')\"><i class='fa fa-users'></i></a>&nbsp;&nbsp;"
													+"<a title='趋势' href=\"javascript:trend('"+ full.ccode+ "', '"+ full.ddesc+ "', '"+ monitorType + "', '"+ quotaCode+ "', '"+ quotaName+ "')\" class='trend-link'><i class='fa fa-line-chart'></i></a>";

		               					}
	               				}
		               			else if(monitorType=="dep"||monitorType=="ward"||monitorType=="clinic")
	               				{// 病组 趋势 病例
		               				if (full.ccode == null) {
		            					return "<a title='病组' class='jumplink' href=\"javascript:alertData()\"><i class='fa fa-list-alt'></i></a>&nbsp;&nbsp;"
		            					+ "<a title='入组病例' class='jumplink' href=\"javascript:alertData()\"><i class='fa fa-users'></i></a>&nbsp;&nbsp;"
		            					+ "<a title='趋势' href=\"javascript:alertData()\" class='trend-link'><i class='fa fa-line-chart'></i></a>";
		            				} else {
		            					return "<a title='病组' class='jumplink' href=\"javascript:departmentDepToDis('" + full.ccode + "','" + full.ddesc + "','" + monitorType + "')\"><i class='fa fa-list-alt'></i></a>&nbsp;&nbsp;"
		            					+ "<a title='入组病例' class='jumplink' href=\"javascript:loadDetail('" + full.ccode + "','" + full.ddesc + "','" + monitorType + "')\"><i class='fa fa-users'></i></a>&nbsp;&nbsp;"
		            					+ "<a title='趋势' href=\"javascript:trend('" + full.ccode + "', '" + full.ddesc + "', '" + monitorType + "', '" + quotaCode + "', '" + quotaName + "')\" class='trend-link'><i class='fa fa-line-chart'></i></a>";
		            				}
	               				}
            				}
						}
						}];
			 	var paramsDataTables={order:[],columnDefs:[{"orderable": false,"targets":[4] }]};
				$("#" + quotaCode + "-table" + tabId).drgsDataTable(columns, data, paramsDataTables);
			})
}
/**
 * 
 * @ Discription:病例明细
 * @Autor ：liuhongjun
 * @param title
 * @param ccode
 * @param monitorType
 * @param quotaCode
 * @returns
 * any
 * ywcCommon.js
 * 2017年6月18日下午6:51:37
 */
function loadDepCaseDtl(title, ccode, monitorType, quotaCode){
	var param=drgUI.setAjaxData(tabId);
	param.caseLinkCode = quotaCode;
	if(ccode){
		if(monitorType == "depGroup"){//兼容多科室的问题
			param.depCode="";//科室code 置为空
			param.deps="";
			param.depGroupCode=ccode;
		}else if(monitorType == "dep"){
			param.depCode=ccode;
		}else if(monitorType == "ward"){
			param.wardCode=ccode;
		}else if(monitorType == "clinic"){
			param.groupName=ccode;
		}else if(monitorType == "protomedicus"){
			param.protomedicus=ccode;
		}else if(monitorType == "physician"){
			param.physician=ccode;
		}else if(monitorType == "resident"){
			param.resident=ccode;
		}else if(monitorType == "mdc"){
			param.mdcCode=ccode;
		}else if(monitorType == "adrg"){
			param.adrgCode=ccode;
		}else if(monitorType == "drgs"){
			param.drgCode=ccode;
		}
	}
	if(monitorType=="All"){
		param.pardepgroupCode="";
	}
	ccode = ccode.replace(/,/g, "")//多科室的时候去掉字符串中的, 不然打不开页面
	openTab('/pages/drgscommon/case.jsp', title+"|"+"病例明细", "caseDtl"+monitorType+ccode+quotaCode, "caseDtl"+monitorType+ccode+quotaCode, param);
}
/**
 * 医政角色病组线 跳往科室线
 * @param code 病组层代码
 * @param desc 病组层描述
 * @param type 监测类型
 */
function departmentDisToDep(code, desc, type){
	var param=drgUI.setAjaxData(tabId);
	param.code = code;
	param.desc = desc;
	param.type = type;
	param.monitorType = type;
	param.previous = type;
	var destUrl = ""; 
	var depLayerName = "";
	var depLayer = "";
	if(commonLayerConfig[1]=="1"){
		destUrl = "/pages/yizheng/ywcDisLineDep.jsp";
		depLayerName = "科室";
		depLayer = "dep";
	}else if(commonLayerConfig[2]=="1"){
		destUrl = "/pages/yizheng/ywcDisLineWard.jsp";
		depLayerName = "病区";
		depLayer = "ward";
	}
	var disLineToDepTitle ="";
	var disLineToDepPageId ="";
	switch(type){
	case "mdc":
		param.mdcCode = code;
		param.mdcDesc = desc;
		disLineToDepTitle = param.mdcCode+"|"+depLayerName;
		disLineToDepPageId = "department"+"-"+"mdc"+"-"+param.mdcCode+"-"+depLayer;
		break;
	case "adrg":
		param.adrgCode = code;
		param.adrgDesc = desc;
		disLineToDepTitle = param.adrgCode+"|"+depLayerName;
		disLineToDepPageId = "department"+"-"+"adrg"+"-"+param.adrgCode+"-"+depLayer;
		break;
	case "drgs":
		param.drgCode = code;
		param.drgDesc = desc;
		disLineToDepTitle = param.drgCode+"|"+depLayerName;
		disLineToDepPageId = "department"+"-"+"drg"+"-"+param.drgCode+"-"+depLayer;
		break;
	}
	openTab(destUrl,disLineToDepTitle,disLineToDepPageId,disLineToDepPageId,param);

}

function departmentDepToDis(code, desc, type) {
	var paramTemp=drgUI.setAjaxData(tabId);
	paramTemp.code = code;
	paramTemp.desc = desc;
	paramTemp.type = type;
	paramTemp.monitorType = type;
	paramTemp.previous = type;
	if(type == "dep"){
		paramTemp.depCode = code;
		paramTemp.depName = desc;
		paramTemp.deps = '';
	}else if(type == "ward"){
		paramTemp.wardCode = code;
		paramTemp.wardName= desc;
	}else if(type == "clinic"){
		paramTemp.groupName = code;
		paramTemp.groupName_desc = desc;
	}else if(type == "protomedicus"){
		paramTemp.protomedicus = code;
		paramTemp.protomedicus_desc = desc;
	}else if(type == "physician"){
		paramTemp.physician = code;
		paramTemp.physician_desc = desc;
	}else if(type == "resident"){
		paramTemp.resident = code;
		paramTemp.resident_desc = desc;
	}
	openTab('/pages/yizheng/ywcDepLineDrg.jsp', desc + "|" + 'DRGs', type + 'DRGs'+ code, type + 'DRGs' + code, paramTemp);
}


function departmentToNextLayer(across,monitorType,code,name){
	var param=drgUI.setAjaxData(tabId);
	param.previous = monitorType;//指示当前的层次
	var destUrl = "";
	var pageId = "";
	switch(monitorType){
	case "dep":
		param.depCode = code;
		param.depName = name;
		if(commonLayerConfig.length>=4)
		{
			if(commonLayerConfig[2]=='1')
			{
				if(across)
				{//病组线下的科室跳往病区
					destUrl = "/pages/yizheng/ywcDisLineWard.jsp";
					pageId = code+"department_Dep_To_DisLineWard";
				}
				else
				{//科室线科室跳往病区
					destUrl = "/pages/yizheng/ywcWard.jsp";
					pageId = code+"department_Dep_To_Ward";
				}
			}
			else if(commonLayerConfig[3]=='1')
			{
				if(across)
				{//病组线下的科室跳往主诊组
					destUrl = "/pages/yizheng/ywcDisLineClinic.jsp";
					pageId = code+"department_Dep_To_DisLineClinic";
				}
				else
				{//科室线科室跳往主诊组
					destUrl = "/pages/yizheng/ywcClinic.jsp";
					pageId = code+"department_Dep_To_Clinic";
				}
			}
		}
		break;
	case "ward":
		param.wardCode = code;
		param.wardName = name;
		if(commonLayerConfig.length>=4){
			if(commonLayerConfig[3]=='1'){
				if(across){//病组线下的病区跳往主诊组
					destUrl = "/pages/yizheng/ywcDisLineClinic.jsp";
					pageId = code+"department_Ward_To_DisLineClinic";
				}else{//科室线病区跳往主诊组
					destUrl = "/pages/yizheng/ywcClinic.jsp";
					pageId = code+"department_Ward_To_Clinic";
				}
			}
		}
		break;
	case "mdc":
		param.mdcCode = code;
		param.mdcName = name;
		if(across){//科室线下的MDC跳往ADRG
			destUrl = "/pages/yizheng/ywcDepLineAdrg.jsp";
			pageId = code+"department_Mdc_To_DepLineAdrg";
		}else{//病组线MDC跳往ADRG
			destUrl = "/pages/yizheng/ywcMdcAdrg.jsp";
			pageId = code+"department_Mdc_To_Adrg";
		}
		
		break;
	case "adrg":
		param.adrgCode = code;
		param.adrgName = name;
		if(across){//科室线下的ADRG跳往DRG
			destUrl = "/pages/yizheng/ywcMdcDrgs.jsp";
			pageId = code+"department_Adrg_To_DepLineDrg";
		}else{//病组线ADRG跳往DRG
			destUrl = "/pages/yizheng/ywcDepLineDrg.jsp";
			pageId = code+"department_Adrg_To_Drg";
		}
		break;
	}
	if(destUrl!=""){
		openTab(destUrl, name+"指标监测",pageId, pageId,param);
	}	
}

function departmentToDRGs(code, desc, type) {
	var paramTemp=drgUI.setAjaxData(tabId);
	paramTemp.code = code;
	paramTemp.desc = desc;
	paramTemp.type = type;
	param.previous = type;
	if(type == "depGroup"){
		paramTemp.depGroupCode = code;
		paramTemp.depGroupName = desc;
	}else if(type == "dep"){
		paramTemp.depCode = code;
		paramTemp.depName= desc;
	}else if(type == "ward"){
		paramTemp.wardCode = code;
		paramTemp.wardName = desc;
	}else if(type == "clinic"){
		paramTemp.groupName = code;
		paramTemp.groupName_desc = desc;
	}else if(type == "protomedicus"){
		paramTemp.protomedicus = code;
		paramTemp.protomedicus_desc = desc;
	}else if(type == "physician"){
		paramTemp.physician = code;
		paramTemp.physician_desc = desc;
	}else if(type == "resident"){
		paramTemp.resident = code;
		paramTemp.resident_desc = desc;
	}
	openTab('/pages/yibao/bingzhong/ybbDepLineDrg.jsp', desc + "|" + 'DRGs', type + 'DRGs'+ code, type + 'DRGs' + code, paramTemp);
}
//加载病例
function loadDetail(code,desc,type){
	var param=drgUI.setAjaxData(tabId);
	param.caseLinkCode = "InCaseCnt";//所有病例图标按钮 均获取入组病例数
	if (type =="drgs") {
		 param.drgCode = code;
		 if(desc == null || desc=="null"){
			desc="未入组";
		}
	}else if (type == "adrg") {
		param.adrgCode = code;
		if(desc == null || desc=="null"){
			desc="未入组";
		}
	}else if (type == "mdc") {
		param.mdcCode = code;
		if(desc == null || desc=="null"){
			desc="未入组";
		}
	}else if(type =="clinic"){
		param.groupName = desc;
		if(desc==null || desc=="null"){
			desc="其他";
		}
	}else if (type == "protomedicus") {
		//主任医师
		param.protomedicus = desc;
		if(desc == null || desc=="null"){
			desc="其他组";
		}
	}else if (type == "physician") {
		//主治医师
		param.physician = desc;
		if(desc == null || desc=="null"){
			desc="其他组";
		}
	}else if (type == "resident") {
		//住院医师
		param.resident = desc;
		if(desc == null || desc=="null"){
			desc="其他组";
		}
	}else if (type == "dep"){
		param.depCode = code;
	}
	openTab('/pages/drgscommon/case.jsp', desc+'病例', code+'Case' , code+'Case', param);
}

//提示未入组数据
function alertData(){
    drgUI.warning("未入组数据") ;
	return;
}


